#ifndef __SYLAR_HTTP_HTTP_PARSER_H__
#define __SYLAR_HTTP_HTTP_PARSER_H__

#include <memory>

#include "http.h"

namespace sylar{
namespace http{

class HttpRequestParser{
public:
	typedef std::shared_ptr<HttpRequestParser> ptr;
	HttpRequestParser();
	size_t  execute(char* data, size_t len);
	int isFinished() ;
	void setError(const int& v){m_error = 1000;}
	int hasError() ;

	uint64_t getContentLength();
	HttpRequest::ptr getData(){ return m_data;}
	const http_parser& getParser() const {return m_parser;}

public:
	static uint64_t GetHttpRequestBufferSize();
	static uint64_t GetHttpRequestMaxBufferSize();
private:
	http_parser m_parser;
	HttpRequest::ptr m_data;
	//1000:invailed method
	//1001
	int m_error;
};

class HttpResponseParser{
public:
	typedef std::shared_ptr<HttpResponseParser> ptr;
	HttpResponseParser();
	size_t  execute(char* data, size_t len, bool chunked);
	int isFinished();
	int hasError();
	void setError(const int& v){m_error = 1000;}

	HttpResponse::ptr getData(){ return m_data;}
	uint64_t getContentLength();

	const httpclient_parser& getParser() const {return m_parser;}

public:
	static uint64_t GetHttpResponseBufferSize();
	static uint64_t GetHttpResponseMaxBufferSize();
private:
	httpclient_parser m_parser;
	HttpResponse::ptr m_data;
	int m_error;
};


}
}
#endif